package com.axxc.cloud.model.exception;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * Form实体基础类
 * Created by zfh on 2018/10/22
 */
public class BaseForm <T> {

    /**
     * JSR 303参数校验
     */
    public void validateParam (T var1) {
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        Validator validator = factory.getValidator();
        Set<ConstraintViolation<T>> violations = validator.validate(var1);
        if (violations.size() > 0) {
            for (ConstraintViolation<T> item: violations) {
                throw new ParamterException(item.getMessage());
            }
        }
    }
}
